home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / dec / qdss / qdlines.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-27  |  4.2 KB  |  130 lines

  1. /***********************************************************
  2. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #include "X.h"            /* for CoordModeOrigin */
  26.  
  27. #include "windowstr.h"
  28. #include "gcstruct.h"
  29. #include "qd.h"
  30. #include "qdgc.h"
  31.  
  32. #define MININT    0x80000000
  33. #define MAXINT    0x7fffffff
  34. #define NOINTERSECTION( pb1, pb2)  \
  35.     (    (pb1)->x1 >= (pb2)->x2  \
  36.       || (pb1)->x2 <= (pb2)->x1  \
  37.       || (pb1)->y1 >= (pb2)->y2  \
  38.       || (pb1)->y2 <= (pb2)->y1)
  39.  
  40. /*
  41.  * does the thin lines case only
  42.  */
  43. void
  44. qdPolylines( pWin, pGC, mode, npt, pptInit)
  45.     WindowPtr        pWin;
  46.     GCPtr        pGC;
  47.     int            mode;           /* Origin or Previous */
  48.     int         npt;            /* number of points */
  49.     register DDXPointPtr pptInit;
  50. {
  51.     register DDXPointPtr abspts;      /* actually, window-relative */
  52.     register int    ip;        /* index into polygon list */
  53.     register int    ir;        /* index into rectangle list */
  54.     BoxRec        ptbounds;    /* used for trivial reject */
  55.     BoxPtr        pclip, pclipi;    /* used for trivial reject */
  56.     int            nclip;        /* used for trivial reject */
  57.     RegionPtr        pdrawreg = QDGC_COMPOSITE_CLIP(pGC);
  58.     Bool        allocated = FALSE;
  59.  
  60.     ptbounds.x1    = MAXINT;
  61.     ptbounds.y1    = MAXINT;
  62.     ptbounds.x2    = MININT;
  63.     ptbounds.y2    = MININT;
  64.  
  65.     if ( npt == 0)        /* make sure abspts[0] is valid */
  66.     return;
  67.     if ( mode == CoordModeOrigin)
  68.     abspts = pptInit;
  69.     else    /* CoordModePrevious */
  70.     {
  71.     abspts = (DDXPointPtr) ALLOCATE_LOCAL( npt * sizeof( DDXPointRec));
  72.         allocated = TRUE;
  73.     abspts[ 0].x = pptInit[ 0].x;
  74.     abspts[ 0].y = pptInit[ 0].y;
  75.     for ( ip=1; ip<npt; ip++)
  76.     {
  77.         abspts[ ip].x = abspts[ ip-1].x + pptInit[ ip].x;
  78.         abspts[ ip].y = abspts[ ip-1].y + pptInit[ ip].y;
  79.     }
  80.     }
  81.  
  82.     /*
  83.      * Prune list of clip rectangles by trivial rejection of entire polyline.
  84.      * Note that we have to add one to the right and bottom bounds, because
  85.      * lines are non-zero width.
  86.      */
  87.     for ( ip=0; ip<npt; ip++)
  88.     {
  89.     ptbounds.x1 = min( ptbounds.x1, abspts[ ip].x);
  90.     ptbounds.y1 = min( ptbounds.y1, abspts[ ip].y);
  91.     ptbounds.x2 = max( ptbounds.x2, abspts[ ip].x+1);
  92.     ptbounds.y2 = max( ptbounds.y2, abspts[ ip].y+1);
  93.     }
  94.     /*
  95.      * translate ptbounds to absolute screen coordinates
  96.      */
  97.     ptbounds.x1 += pWin->absCorner.x;
  98.     ptbounds.y1 += pWin->absCorner.y;
  99.     ptbounds.x2 += pWin->absCorner.x;
  100.     ptbounds.y2 += pWin->absCorner.y;
  101.  
  102.     nclip = 0;
  103.     ir = REGION_NUM_RECTS(pdrawreg);
  104.     pclip = (BoxPtr)ALLOCATE_LOCAL( ir * sizeof(BoxRec));
  105.     pclipi = REGION_RECTS(pdrawreg);
  106.     for (; --ir >= 0; pclipi++)
  107.     if ( ! NOINTERSECTION( &ptbounds, pclipi)
  108.         pclip[ nclip++] = *pclipi;
  109.  
  110.     /*
  111.      * draw the polyline
  112.      */
  113.     tlzlines( pWin, pGC, nclip, pclip, npt, abspts);
  114.  
  115.     /*
  116.      * X11 wants the last pointed drawn, if not coincident with the first.
  117.      */
  118.     if (   abspts[ 0].x == abspts[ npt-1].x
  119.     && abspts[ 0].y == abspts[ npt-1].y)
  120.     return;
  121.     abspts[ 1] = abspts[ 0] = abspts[ npt-1];
  122.     abspts[ 1].x++;    /* a length 1 line, direction shouldn't matter */
  123.  
  124.     tlzlines( pWin, pGC, nclip, pclip, 2, abspts);
  125.  
  126.     DEALLOCATE_LOCAL(pclip);
  127.     if (allocated) DEALLOCATE_LOCAL(abspts);
  128.         
  129. }
  130.